 import { getToken, removeToken, removeData  } from '@/utils/auth'//获取token
function request(obj) {
    return new Promise((resolve, reject) => {
        // const baseUrl = "https://blind.sintro.cn/prod-api"
		const baseUrl = "https://123.56.189.119:8544"
		// const baseUrl = "https://www.sdtaiyi.top:8544"
		// const baseUrl = "http://172.20.202.23:80/dev-api"
		//const baseUrl = "http://172.20.202.37/dev-api"
        var method = obj.method || "GET";
        var url = baseUrl + obj.url || "";
        var data = obj.params || obj.data || {};
		let token = getToken();
		
		console.log(token);
        var header = obj.header || {
            'Content-Type': obj.contentType || 'application/json',
            'Authorization':  token
        }
        uni.request({
            url: url,
            data: data,
            method: method,
            header: header,
            success: ((res) => {
                if (res.statusCode === 403 || res.statusCode === 401 || res.data.code == 401) {
					//清除用户信息
					removeToken();
					removeData();
					
                    uni.reLaunch({
						// 错误处理，返回登录页
                        url: '/pages/login/index'
                    })
                } else if (res.statusCode === 200) {
                    // console.log('request', res)
                    // uni.showToast({
                    //     title: '请求接口成功200',
                    //     duration: 2000
                    // })
                    resolve(res)
                }
            }),
            fail: ((err) => {
                uni.showToast({
                    title: '请求接口失败',
                    duration: 2000
                })
                reject(err)
            })
        })
    })
}
export default request
